package com.bit.frige;

import java.util.List;   

import com.bit.frige.DB.FoodDTO;
import android.content.*;
import android.view.*;
import android.widget.*;

public class ImageAdapter extends BaseAdapter {
   Context mContext;
   List<FoodDTO> foodlist;

   public ImageAdapter(Context context, List<FoodDTO> FoodDTO) {
      mContext = context;
      foodlist = FoodDTO;
   }

   @Override
   public View getView(int position, View convertView, ViewGroup parent) {
      // 재활용할 뷰가 convertView에 들어온다.

		ImageKikanView kikanview;
		if (convertView == null) {
			kikanview = new ImageKikanView(mContext, foodlist.get(position));
		} else {
			kikanview = (ImageKikanView) convertView;
			kikanview.setIcon(foodlist.get(position).getCateno(),foodlist.get(position).getSelfdate());
			kikanview.setText(foodlist.get(position).getFoodname(), foodlist
					.get(position).getSelfdate());
		}

      return kikanview;

   }

   @Override
   public int getCount() {

      //return foodlist.size();
      if(foodlist.size()>=6){
         return 6;
      }else{
         return foodlist.size();
      }
      //최대 6개까지 등록

   }

   @Override
   public Object getItem(int position) { // 데이터의 원본값을 반환한다.
      return foodlist.get(position);
   }

   @Override
   public long getItemId(int position) {

      return position;
   }

   public void addItem(FoodDTO it) {
      foodlist.add(it);
   }

   public void setListItems(List<FoodDTO> lit) {
      foodlist = lit;
   }

   public boolean areAllItemsSelectable() {
      return false;
   }

   public boolean isSelectable(int position) {
      return true;
   }

}
